package com.jieshuibao.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jieshuibao.common.config.Const;
import com.jieshuibao.model.db.Category;
import com.jieshuibao.model.db.Company;
import com.jieshuibao.model.db.Counselor;
import com.jieshuibao.model.db.Duty;
import com.jieshuibao.model.db.Level;
import com.jieshuibao.model.db.QuestionSecretly;
import com.jieshuibao.model.db.QuestionUserEx;
import com.jieshuibao.model.db.User;
import com.jieshuibao.model.db.UserExample;
import com.jieshuibao.model.domain.AddAdmireResponse;
import com.jieshuibao.model.domain.AllCompanyUserResponse;
import com.jieshuibao.model.domain.CookieUser;
import com.jieshuibao.model.domain.EditUserRequest;
import com.jieshuibao.model.domain.EditUserResponse;
import com.jieshuibao.model.domain.FindPwdOneRequest;
import com.jieshuibao.model.domain.FindPwdOneResponse;
import com.jieshuibao.model.domain.Integrals;
import com.jieshuibao.model.domain.LoginResponse;
import com.jieshuibao.model.domain.QuestionRequest;
import com.jieshuibao.model.domain.SecretlyQuestionResponse;
import com.jieshuibao.model.domain.UpgradeConsultRequest;
import com.jieshuibao.model.domain.UpgradeCounselorResponse;
import com.jieshuibao.model.domain.UpgradeEnterpriserRequest;
import com.jieshuibao.service.AnswerUserService;
import com.jieshuibao.service.CategoryService;
import com.jieshuibao.service.ChangeAdminService;
import com.jieshuibao.service.CompanyService;
import com.jieshuibao.service.CounselorDutyService;
import com.jieshuibao.service.CounselorService;
import com.jieshuibao.service.IntegralService;
import com.jieshuibao.service.LevelService;
import com.jieshuibao.service.QuestionUserService;
import com.jieshuibao.service.RedEnvelopesService;
import com.jieshuibao.service.RedisService;
import com.jieshuibao.service.UserCompanyService;
import com.jieshuibao.service.UserCounselorService;
import com.jieshuibao.service.UserService;
import com.jieshuibao.util.Base64ForImg;
import com.jieshuibao.util.IDCardUtil;
import com.jieshuibao.util.StringUtils;
import com.jieshuibao.util.UUIDGenerator;

@Controller
@RequestMapping(value = "/user")
public class UserController {

	private static final Logger logger = LoggerFactory
			.getLogger("UserController.class");

	private static final ObjectMapper mapper = new ObjectMapper();

	@Resource
	private UserService userService;
	@Resource
	private RedisService redisService;
	@Resource
	private CompanyService companyService;
	@Resource
	private UserCounselorService userCounselorService;
	@Resource
	private QuestionUserService questionUserService;
	@Resource
	private AnswerUserService answerUserService;
	@Resource
	private CounselorService counselorService;
	@Resource
	private LevelService levelService;
	@Resource
	private CategoryService categoryService;
	@Resource
	private ChangeAdminService changeAdminService;
	@Resource
	private UserCompanyService userCompanyService;
	@Resource
	private CounselorDutyService counselorDutyService;
	@Resource
	private RedEnvelopesService redEnvelopesService;
	@Resource
	private IntegralService IntegralService;
	@Value("${images.basePath}")
	private String imagesBasePath;

	@Value("${head.images.path}")
	private String headImagespath;

	@Value("${cert.images.path}")
	private String certImagesPath;

	@Value("${cert.images.url}")
	private String certImagesUrl;

	@Value("${head.images.url}")
	private String headImagesUrl;

	@Value("${question.images.url}")
	private String questionImagesUrl;

	// 用户编辑资料
	@ResponseBody
	@RequestMapping(value = "/editUser", method = RequestMethod.POST)
	public Object editUser(HttpServletRequest request,
			@RequestBody EditUserRequest editUserRequest) {

		EditUserResponse editUserResponse = new EditUserResponse();
		try {
			logger.debug("接收：" + mapper.writeValueAsString(editUserRequest));
			
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				String companyName = editUserRequest.getCompanyName();
				if (cookieUser != null) {
					String phoneNum = cookieUser.getPhoneNumber();
					String phone = cookieUser.getPhone();
					
					//不要忘记添加职务属性
					if (phoneNum != null) {
						List<String> whithList=Arrays.asList(Const.WHITELIST);
						String realName = editUserRequest.getRealName();
						String address = editUserRequest.getAddress();
						String province = editUserRequest.getProvince();//新加属性 省份
						
						Integer sex = editUserRequest.getSex();
						String position = editUserRequest.getPosition();
						String userName = editUserRequest.getUserName();
						String trade = editUserRequest.getTrade();
						
						User user2 = userService.getUserByPhoneNumber(phoneNum);
						Integer companyRole = user2.getCompanyRole();
						String companyName2 = user2.getCompanyName();
						String realName2 = user2.getRealName();
						//String userName2 = user2.getUserName();
						String province2 = user2.getProvince();
						
						String address2 = user2.getAddress();
						User user = new User();
						if (StringUtils.isNotBlank(userName)) {
							user.setUserName(userName);
						}
						/*if (StringUtils.isBlank(userName)) {
							if (StringUtils.isBlank(userName2)) {
								editUserResponse.setCode("3");
								editUserResponse.setDes("真实姓名不能为空！");
								return editUserResponse;
								
							}
							
						}else {
							user.setUserName(userName);
						}*/
						
						if (StringUtils.isNotBlank(trade)) {
							user.setTrade(trade);
						}
						user.setPhoneNumber(phoneNum);
						if(realName==null||realName.equals("")){
							if(realName2==null||realName2.equals("")){
								//真实姓名不能为空
								editUserResponse.setCode("3");
								editUserResponse.setDes("昵称不能为空");
								return editUserResponse;
							}
						}else {
							if(!whithList.contains(phone)&&realName.contains("解税宝")){
								editUserResponse.setCode("3");
								editUserResponse.setDes("姓名不合法");
								return editUserResponse;
								
							}else {
								user.setRealName(realName);
							}
						}
						if(position!=null&&!position.equals("")){
							user.setPosition(position);
						}
						
						if(StringUtils.isBlank(address)||StringUtils.isBlank(province)){
							if(StringUtils.isBlank(address2)||StringUtils.isBlank(province2)){
								//地址不能为空
								editUserResponse.setCode("3");
								editUserResponse.setDes("地址不能为空");
								return editUserResponse;
							}
							
						}else {
							user.setAddress(address);
							user.setProvince(province);
						}
						
						if(companyName==null||companyName.equals("")){
//							if(companyName2==null||companyName2.equals("")){
//								//公司名不能为空
//								editUserResponse.setCode("3");
//								editUserResponse.setDes("公司名不能为空");
//								return editUserResponse;
//							}
							
						}else {
							if(companyRole == 1 || companyRole == 2){
								if (!companyName.equals(companyName2)) {
									// 你是企业用户公司名不能修改
									editUserResponse.setCode("3");
									editUserResponse.setDes("你是企业用户公司名不能修改");
									return editUserResponse;
								}
							}else {
								if(!whithList.contains(phone)&&companyName.contains("解税宝")){
									editUserResponse.setCode("3");
									editUserResponse.setDes("公司名不合法");
									return editUserResponse;
								}else {
									user.setCompanyName(companyName);

								}
							}
						}
						if(sex==null||sex==0){
							user.setSex(1);
						}else {
							user.setSex(sex);
						}
						
						String birthdayDate = editUserRequest.getBirthdayDate();
						try {
							if (birthdayDate != null&&!birthdayDate.equals("")) {
								java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
										"yyyy-MM-dd");
								java.util.Date utilDate = sdf.parse(birthdayDate);
								user.setBirthdayDate(utilDate);
							}
						} catch (Exception e) {
							user.setBirthdayDate(null);
						}
						String headImage = editUserRequest.getHeadImage();
						if (headImage != null && !headImage.equals("")) {
							/*long headTime = new Date().getTime();
							String headString = String.valueOf(headTime);*/
							String uuid = UUIDGenerator.getUUID();
							
							Base64ForImg.GenerateImage(headImage,
									imagesBasePath + headImagespath + uuid);
							user.setHeadImage(uuid);
						}
						userService.updateUser(user);
						IntegralService.integralCompleteData(phoneNum);
						editUserResponse.setCode("1");
						editUserResponse.setDes("修改成功！");
						editUserResponse.setHeadImagesUrl(headImagesUrl);

					} else {
						// 未登录
						editUserResponse.setCode("2");
						editUserResponse.setDes("重新登录！");
					}
				} else {
					// 未登录
					editUserResponse.setCode("2");
					editUserResponse.setDes("重新登录！！");
				}

			logger.info("返回：" + mapper.writeValueAsString(editUserResponse));
		} catch (Exception e) {

			e.printStackTrace();
			editUserResponse.setCode("0");
			editUserResponse.setDes("系统繁忙");
		}

		return editUserResponse;
	}

	// 成为企业管理员接口
	@RequestMapping(value = "/upEnterpriser", method = RequestMethod.POST)
	@ResponseBody
	public Object upgradeEnterpriser(HttpServletRequest request,
			@RequestBody UpgradeEnterpriserRequest upgradeEnterpriserRequest) {
		AddAdmireResponse addAdmireResponse = new AddAdmireResponse();

		try {
			logger.info("接收："
					+ mapper.writeValueAsString(upgradeEnterpriserRequest));
			// cookieId = request.getHeader("cookieId");
			//String companyName = upgradeEnterpriserRequest.getCompanyName();
			//String licenseImage = upgradeEnterpriserRequest.getLicenseImage();
			//String headImage = upgradeEnterpriserRequest.getHeadImage();
			addAdmireResponse.setCode("3");
			addAdmireResponse.setDes("请更新版本");
			
			/*if (cookieId != null) {
				// String phoneNum = redisService.get(cookieId);
				CookieUser cookieUser = redisService.getObejct(cookieId,
						CookieUser.class);
				if (cookieUser != null) {
					String phoneNum = cookieUser.getPhoneNumber();
					if (phoneNum != null) {
						// 可以加 此用户是否已经完善资料
						List<String> whithList=Arrays.asList(Const.WHITELIST);
						if (companyName != null && licenseImage != null
								&& !companyName.equals("")
								&& !licenseImage.equals("")&&headImage!=null&&!headImage.equals("")) {
							User user2 = userService.getUserByPhoneNumber(phoneNum);
							if(user2!=null){
								if(!whithList.contains(phoneNum)&&companyName.contains("解税宝")){
									//数据格式错误
									addAdmireResponse.setCode("3");
									addAdmireResponse.setDes("公司名不合法");
								}else {
									Integer companyRole = user2.getCompanyRole();
									if(companyRole==1){
										addAdmireResponse.setCode("3");
										addAdmireResponse.setDes("已经是企业管理员");
										//已经是企业管理员
									}else if (companyRole==2) {
										addAdmireResponse.setCode("3");
										addAdmireResponse.setDes("你已经是其它企业的普通用户");
										//你已经加入其它企业的普通用户
									}else if(companyRole==0){
										//Double vipBalance = user2.getVipBalance();
										Company company = new Company();
										//company.setBusinessBalance(vipBalance);
										User user = new User();
										company.setCompanyName(companyName);
										company.setPhoneNumber(phoneNum);
										company.setStatus(2);// 直接审核通过
										String companyUuid = UUIDGenerator.getUUID();
										company.setUuid(companyUuid);
										Base64ForImg.GenerateImage(licenseImage,
												imagesBasePath + certImagesPath + phoneNum
														+ "_license");
										company.setLicenseImage(phoneNum + "_license");
										if (headImage != null && !headImage.equals("")) {
											String uuid = UUIDGenerator.getUUID();
											Base64ForImg.GenerateImage(headImage,
													imagesBasePath + headImagespath + uuid);
											company.setCompanyLog(uuid);
										}
										user.setCompanyName(companyName);
										user.setCompanyRole(1);
										//user.setVipBalance(0.0); 钱不合并了
										user.setCompanyUuid(companyUuid);
										user.setPhoneNumber(phoneNum);
										companyService.uodateUserAndAddCompany(user, company);
										addAdmireResponse.setCode("1");
										addAdmireResponse.setDes("申请成功");

									
									}else {
										addAdmireResponse.setCode("3");
										addAdmireResponse.setDes("数据格式错误");
										//数据格式错
									}
									
									
								}
								
							}else {
								//数据格式错误
								addAdmireResponse.setCode("2");
								addAdmireResponse.setDes("请重新登录");
							}
							
					} else {
							// 数据格式错误 营业执照和公司名称不能为空
							addAdmireResponse.setCode("3");
							addAdmireResponse.setDes("营业执照或者公司和公司名称不能为空");
						}
					} else {
						// 重新登录
						addAdmireResponse.setCode("2");
						addAdmireResponse.setDes("请重新登录！");
					}
				} else {
					//
					// 重新登录
					addAdmireResponse.setCode("2");
					addAdmireResponse.setDes("请重新登录！");
				}

			} else {
				// 重新登录
				addAdmireResponse.setCode("2");
				addAdmireResponse.setDes("请重新登录！");
			}
			logger.info("返回：" + mapper.writeValueAsString(addAdmireResponse));*/
		} catch (Exception e) {

			e.printStackTrace();
			addAdmireResponse.setCode("0");
			addAdmireResponse.setDes("系统繁忙请稍后再试！");
		}

		return addAdmireResponse;
	}


	// 升级为咨询师用户接口和编辑资料接口
	@RequestMapping(value = "/counselor", method = RequestMethod.POST)
	@ResponseBody
	public Object upgradeConsult2(HttpServletRequest request,
			@RequestBody UpgradeConsultRequest upgradeConsultRequest) {
		UpgradeCounselorResponse upgradeCounselorResponse = new UpgradeCounselorResponse();

		try {
			logger.info("接收："
					+ mapper.writeValueAsString(upgradeConsultRequest));
			
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if (cookieUser != null) {
					String phoneNum = cookieUser.getPhoneNumber();
					String phone = cookieUser.getPhone();
					
					if (phoneNum != null) {
						User user2 = userService.getUserByPhoneNumber(phoneNum);
						if(user2!=null){
							
							User user = new User();
							user.setPhoneNumber(phoneNum);
							Integer role = user2.getRole();
							String headImage = upgradeConsultRequest.getHeadImage();
							String headImage2 = user2.getHeadImage();
							
							String experience = upgradeConsultRequest.getExperience();
									
							String position = upgradeConsultRequest.getPosition();
							
							String classicalCase = upgradeConsultRequest.getClassicalCase();
									
							List<String> caseImages = upgradeConsultRequest.getCaseImages();
									
							List<String> accountantImage = upgradeConsultRequest.getAccountantImage();// 会计照片

							String adept = upgradeConsultRequest.getAdep();// 擅长业务
							
							String companyName = upgradeConsultRequest.getCompanyName();
									
							String companyName2 = user2.getCompanyName();
							Integer companyRole = user2.getCompanyRole();
							List<String> lawyerImage = upgradeConsultRequest.getLawyerImage();// 律师照片
							List<String> taxImage = upgradeConsultRequest.getTaxImage();// 税务师资格证
							
							String idCard = upgradeConsultRequest.getIdCard();//身份证号码
							String idCardFront = upgradeConsultRequest.getIdCardFront();//身份证正面
							String idCardBack = upgradeConsultRequest.getIdCardBack();//身份证反面
							String address = upgradeConsultRequest.getAddress();
							String address2 = user2.getAddress();
							String province = upgradeConsultRequest.getProvince();//省
							String userName = upgradeConsultRequest.getUserName();//真实姓名
							String userName2 = user2.getUserName();
							if (StringUtils.isBlank(userName)) {
							if (StringUtils.isBlank(userName2)) {
								upgradeCounselorResponse.setCode("3");
								upgradeCounselorResponse.setDes("真实姓名不能为空！");
								return upgradeCounselorResponse;
								
							}
							
							}else {
							user.setUserName(userName);
							}
							String realName = upgradeConsultRequest.getRealName();
							String realName2 = user2.getRealName();
							String province2 = user2.getProvince();
							
							Integer sex = upgradeConsultRequest.getSex();
							String birthdayDate = upgradeConsultRequest
									.getBirthdayDate();
							if(position!=null&&!position.equals("")){
								user.setPosition(position);
							}
							if (sex !=null) {
								if(sex==1||sex==2){
									user.setSex(sex);
								}
							}
							String trade = upgradeConsultRequest.getTrade();
							if (StringUtils.isNotBlank(trade)) {
								user.setTrade(trade);
							}
							List<String> whithList=Arrays.asList(Const.WHITELIST);
							if (birthdayDate != null && !birthdayDate.equals("")) {
								java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
										"yyyy-MM-dd");
								java.util.Date utilDate;
								try {
									utilDate = sdf.parse(birthdayDate);
									user.setBirthdayDate(utilDate);
								} catch (Exception e) {
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("出生日期格式错误");
									return upgradeCounselorResponse;
								}
							}
							if (headImage == null || headImage.equals("")) {
									if(headImage2==null||headImage2.equals("")){
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("头像不能为空");
										return upgradeCounselorResponse;
									}
							}else {
								String uuid = UUIDGenerator.getUUID();
								Base64ForImg.GenerateImage(headImage,
										imagesBasePath + headImagespath + uuid);
								user.setHeadImage(uuid);
							}
							if(StringUtils.isBlank(address)||StringUtils.isBlank(province)){
								if(StringUtils.isBlank(address2)||StringUtils.isBlank(province2)){
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("地址不能为空");
									return upgradeCounselorResponse;
								}
							}else {
								user.setAddress(address);
								user.setProvince(province);
							}
							if(realName==null||realName.equals("")){
								if(realName2==null||realName2.equals("")){
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("昵称不能为空");
									return upgradeCounselorResponse;
								}
							}else {
								if(!whithList.contains(phone)&&realName.contains("解税宝")){
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("昵称不合法");
									return upgradeCounselorResponse;
								}else {
									user.setRealName(realName);
								}
							}
							if(companyName==null||companyName.equals("")){
								if(companyName2==null||companyName2.equals("")){
									//公司名不能为空
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("公司名不能为空");
									return upgradeCounselorResponse;
								}
							}else {
								if(companyRole == 1 || companyRole == 2){
									if (!companyName.equals(companyName2)) {
										// 你是企业用户公司名不能修改
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("你是企业用户公司名不能修改");
										return upgradeCounselorResponse;
									}
								}else {
									if(!whithList.contains(phone)&&companyName.contains("解税宝")){
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("公司名不合法");
										return upgradeCounselorResponse;
									}else {
										user.setCompanyName(companyName);
									}
								}
							}
							Counselor counselor2 = new Counselor();
							String uuid = UUIDGenerator.getUUID();
							
							if(experience!=null&&!experience.equals("")){
								counselor2.setExperience(experience);
							}
							if(classicalCase!=null&&!classicalCase.equals("")){
								counselor2.setClassicalCase(classicalCase);
							}
							if(adept!=null&&!adept.equals("")){
								counselor2.setAdept(adept);
							}
							if (caseImages != null&&caseImages.size()>0) {
								int i = 1;
								List<String> imgs = new ArrayList<String>();
								for (String image : caseImages) {
									// 生成图片
									Base64ForImg.GenerateImage(image,
											imagesBasePath + certImagesPath
													+ uuid
													+ "_case" + i);
									imgs.add(uuid + "_case" + i);
									i++;
								}
								// 转json
								ObjectMapper mapper = new ObjectMapper();
								String imgString = mapper.writeValueAsString(imgs);
								counselor2.setCaseImages(imgString);
							}
							if (accountantImage != null && accountantImage.size()>0) {
								int i = 1;
								List<String> imgs = new ArrayList<String>();
								for (String image : accountantImage) {
									// 生成图片
									Base64ForImg.GenerateImage(image,
											imagesBasePath + certImagesPath
													+ uuid + "_account"
													+ i);
									imgs.add(uuid + "_account" + i);
									i++;
								}
								// 转json
								ObjectMapper mapper = new ObjectMapper();
								String imgString = mapper
										.writeValueAsString(imgs);
								counselor2.setAccountantImage(imgString);
							}else {
								counselor2.setAccountantImage("");
								
							}
							if (lawyerImage != null
									&& lawyerImage.size()>0) {

								int i = 1;
								List<String> imgs = new ArrayList<String>();
								for (String image : lawyerImage) {
									// 生成图片
									Base64ForImg.GenerateImage(image,
											imagesBasePath + certImagesPath
													+ uuid + "_lawyer"
													+ i);
									imgs.add(uuid + "_lawyer" + i);
									i++;
								}
								// 转json
								ObjectMapper mapper = new ObjectMapper();
								String imgString = mapper
									.writeValueAsString(imgs);
								counselor2.setLawyerImage(imgString);
							}else {
								counselor2.setLawyerImage("");
							}

							if (taxImage != null && taxImage.size()>0) {
								int i = 1;
								List<String> imgs = new ArrayList<String>();
								for (String image : taxImage) {
									// 生成图片
									Base64ForImg.GenerateImage(image,
											imagesBasePath + certImagesPath
													+ uuid + "_tax"
													+ i);
									imgs.add(uuid + "_tax" + i);
									i++;
								}
								ObjectMapper mapper = new ObjectMapper();
								String imgString = mapper
										.writeValueAsString(imgs);
								counselor2.setTaxImage(imgString);
							}else {
								counselor2.setTaxImage("");
							}
							
							counselor2.setApplyDate(new Date());
							String counselorUuid = user2.getCounselorUuid();
							Counselor counselor = counselorService.getCounselorByUuid(counselorUuid);
							//-----------------------当身份证信息不为空时，进行赋值----------------------------------
							//对于身份证号及正反面的校验
							if (StringUtils.isNotBlank(idCard)) {
								if(!IDCardUtil.isIDCard(idCard)){
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("身份证号格式错误");
									return upgradeCounselorResponse;
								}
								counselor2.setIDCard(idCard);
//								upgradeCounselorResponse.setCode("3");
//								upgradeCounselorResponse.setDes("身份证号不能为空");
//								return upgradeCounselorResponse;
							}
							if (StringUtils.isNotBlank(idCardFront)) {
								String imgUuid = UUIDGenerator.getUUID();
								Base64ForImg.GenerateImage(idCardFront,imagesBasePath + certImagesPath + imgUuid + "_idCardFront");
								counselor2.setIDCardFront(imgUuid + "_idCardFront");
//								upgradeCounselorResponse.setCode("3");
//								upgradeCounselorResponse.setDes("身份证正面照片不能为空");
//								return upgradeCounselorResponse;
							}
							if (StringUtils.isNotBlank(idCardBack)) {
								String imgUuid = UUIDGenerator.getUUID();
								Base64ForImg.GenerateImage(idCardBack,imagesBasePath + certImagesPath + imgUuid + "_idCardBack");
								counselor2.setIDCardBack(imgUuid + "_idCardBack");
//								upgradeCounselorResponse.setCode("3");
//								upgradeCounselorResponse.setDes("身份证反面照片不能为空");
//								return upgradeCounselorResponse;
							}
							//-----------------------当身份证信息不为空时，进行赋值---------------------
							if(role==1){
								user.setRole(1);
								if(counselor==null){
									if(adept!=null&&!adept.equals("")){
										//第一次申请时，对身份证信息必传判断
										if(StringUtils.isBlank(idCard)){
											upgradeCounselorResponse.setCode("3");
											upgradeCounselorResponse.setDes("身份证号不能为空");
											return upgradeCounselorResponse;
										}
										if(StringUtils.isBlank(idCardFront)){
											upgradeCounselorResponse.setCode("3");
											upgradeCounselorResponse.setDes("身份证正面照片不能为空");
											return upgradeCounselorResponse;
										}
										if(StringUtils.isBlank(idCardBack)){
											upgradeCounselorResponse.setCode("3");
											upgradeCounselorResponse.setDes("身份证反面照片不能为空");
											return upgradeCounselorResponse;
										}
										counselor2.setAdept(adept);
										if((lawyerImage!=null&&lawyerImage.size()>0)||(accountantImage!=null&&accountantImage.size()>0)||(taxImage!=null&&taxImage.size()>0)){
											counselor2.setStatus(1);
											counselor2.setUserPhoneNumber(phoneNum);
											counselor2.setUuid(uuid);
											user.setCounselorUuid(uuid);
											userCounselorService.updateUserAndAddCounselor(user, counselor2);
											IntegralService.integralCompleteData(phoneNum);
											
											upgradeCounselorResponse.setCode("1");
											upgradeCounselorResponse.setDes("资料提交成功，请耐心等待审核！");
											upgradeCounselorResponse.setCounselorStatus(1);
										}else {
											//三个证件必须传一个
											upgradeCounselorResponse.setCode("3");
											upgradeCounselorResponse.setDes("证件必须上传！");
										}
									}else {
										//带* 的是必填字段擅长业务必填
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("擅长业务必填");
									}
								}else {
									//第二次申请
									if((headImage!=null&&!headImage.equals(""))
											||(experience!=null&&!experience.equals(""))
											||(classicalCase!=null&&!classicalCase.equals(""))
											||(caseImages!=null&&caseImages.size()>0)
											||(accountantImage!=null&&accountantImage.size()>0)
											||(adept!=null&&!adept.equals(""))
											||(companyName!=null&&!companyName.equals(""))
											||(lawyerImage!=null&&lawyerImage.size()>0)
											||(taxImage!=null&&taxImage.size()>0)
											||(address!=null&&!address.equals(""))
											||(realName!=null&&!realName.equals(""))
											||(position!=null&&!position.equals(""))
											||(sex==null)
											||(birthdayDate!=null&&!birthdayDate.equals(""))
											||(province!=null)&&!province.equals("")
											//---------------------第二次申请时，没有修改任何信息的判断条件：增加身份证信息判断--------------------
											|| StringUtils.isNotBlank(idCard)
											|| StringUtils.isNotBlank(idCardFront)
											|| StringUtils.isNotBlank(idCardFront)){
										counselor2.setStatus(1);
										counselor2.setUserPhoneNumber(phoneNum);
										counselor2.setUuid(counselorUuid);
										userCounselorService.updateUserCounselor(user,
												counselor2);
										upgradeCounselorResponse.setCode("1");
										upgradeCounselorResponse.setDes("修改成功，请等待审核！");
									}else {
										//没有修改任何信息
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("没有修改任何信息");
									}
								}
							}else {
								if(counselor!=null){
									//role 2
									if((headImage!=null&&!headImage.equals(""))
											||(experience!=null&&!experience.equals(""))
											||(classicalCase!=null&&!classicalCase.equals(""))
											||(caseImages!=null&&caseImages.size()>0)
											||(accountantImage!=null&&accountantImage.size()>0)
											||(adept!=null&&!adept.equals(""))
											||(companyName!=null&&!companyName.equals(""))
											||(lawyerImage!=null&&lawyerImage.size()>0)
											||(taxImage!=null&&taxImage.size()>0)
											||(address!=null&&!address.equals(""))
											||(realName!=null&&!realName.equals(""))
											||(position!=null&&!position.equals(""))
											||(sex==null)
											||(birthdayDate!=null&&!birthdayDate.equals(""))
											||(province!=null)&&!province.equals("")
											||(userName!=null&&!userName.equals(""))
											//------------------没有修改任何信息的判断条件：增加身份证信息------------------------
											|| StringUtils.isNotBlank(idCard)
											|| StringUtils.isNotBlank(idCardFront)
											|| StringUtils.isNotBlank(idCardFront)){
										counselor2.setStatus(1);
										counselor2.setUserPhoneNumber(phoneNum);
										counselor2.setUuid(counselorUuid);
										user.setRole(1);
										userCounselorService.updateUserCounselor(user,
												counselor2);
										upgradeCounselorResponse.setCode("1");
										upgradeCounselorResponse.setDes("提交资料成功");
										
									}else{
										//没有修改任何信息
										upgradeCounselorResponse.setCode("3");
										upgradeCounselorResponse.setDes("没有修改任何信息");
									}
								}else {
									//
									upgradeCounselorResponse.setCode("3");
									upgradeCounselorResponse.setDes("数据错误");
								}
							}
							
							
						}else {
							// 未登录
							upgradeCounselorResponse.setCode("2");
							upgradeCounselorResponse.setDes("请重新登陆");
						}
					} else {
						// 未登录
						upgradeCounselorResponse.setCode("2");
						upgradeCounselorResponse.setDes("请重新登陆");
					}
				} else {
					// 未登录
					upgradeCounselorResponse.setCode("2");
					upgradeCounselorResponse.setDes("请重新登陆");
				}

			logger.info("返回："
					+ mapper.writeValueAsString(upgradeCounselorResponse));
		} catch (Exception e) {

			e.printStackTrace();
			upgradeCounselorResponse.setCode("0");
			upgradeCounselorResponse.setDes("系统繁忙请稍后再试！");
		}

		return upgradeCounselorResponse;
	}

	// 我的清单里偷偷看列表
	@RequestMapping(value = "/secretly", method = RequestMethod.POST)
	@ResponseBody
	public Object oneselfSecretltyQuestion(HttpServletRequest request,
			@RequestBody QuestionRequest questionRequest) {
		SecretlyQuestionResponse secretlyQuestionResponse = new SecretlyQuestionResponse();
		try {
			logger.info("接收：" + mapper.writeValueAsString(questionRequest));
			//String cookieId = request.getHeader("cookieId");
			//if (cookieId != null) {
				// String phoneNum = redisService.get(cookieId);
				//CookieUser cookieUser = redisService.getObejct(cookieId,
						//CookieUser.class);
			CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if(cookieUser!=null){
					String phoneNum = cookieUser.getPhoneNumber();
					if (phoneNum != null) {
						QuestionSecretly questionSecretly = new QuestionSecretly();
						int sinceId = questionRequest.getSinceId();
						int maxId = questionRequest.getMaxId();

						if (sinceId <= 0) {
							sinceId = 1;
						}
						if (maxId <= 0 || maxId < sinceId) {
							maxId = sinceId;
						}
						questionSecretly.setPageIndex(sinceId - 1);
						questionSecretly.setPageSize(maxId - sinceId + 1);
						questionSecretly.setPhoneNumber(phoneNum);
						List<QuestionUserEx> list = questionUserService
								.getPageByNum(questionSecretly);
					/*	for (QuestionUserEx question : list) {
							//QuestionUserExample questionUserExample2 = new QuestionUserExample();

							List<Answer> answers = answerUserService.getAnswer(
									question.getUuid(), 2);
							if (null != answers&&answers.size()>0) {
								Answer answer = answers.get(0);
								question.setApproveNum(answer.getApproveNum());// 赞成数目
							}
							Criteria criteria2 = questionUserExample2
									.createCriteria();
							criteria2.andQuestionUuidEqualTo(question.getUuid());
							int lookNum = questionUserService
									.countUser(questionUserExample2);
							question.setLookNum(lookNum);// 看过的数量
							
							String counselorDuty = question.getCounselorDuty();
							if(counselorDuty!=null&&!counselorDuty.equals("")){
								
								String counselorDutyName = counselorDutyService.getCounselorDutyName(counselorDuty);
								question.setCounselorDuty(counselorDutyName);
								StringBuilder stringBuilder=new StringBuilder();
								String[] dutys = counselorDuty.split(",");
								if(dutys!=null){
									for (String id : dutys) {
										if(id!=null&&!id.equals("")){
											Duty duty = counselorDutyService.getDutyById(id);
											if(duty!=null){
												stringBuilder.append(duty.getDutyName()+" ");
											}
											
										}
										
									}
									question.setCounselorDuty(stringBuilder.toString());
								}
								
							}
						
							
						}*/
						secretlyQuestionResponse.setCode("1");
						secretlyQuestionResponse.setSinceId(sinceId);
						secretlyQuestionResponse
								.setMaxId(sinceId + list.size() - 1);
						secretlyQuestionResponse.setRows(list.size());
						secretlyQuestionResponse
								.setQuestionImagesUrl(questionImagesUrl);
						// System.out.println(questionImagesUrl);
						secretlyQuestionResponse.setQuestions(list);
					} else {
						// 重新登录
						secretlyQuestionResponse.setCode("2");
						secretlyQuestionResponse.setDes("请重新登陆");
					}
				}else {
					secretlyQuestionResponse.setCode("2");
					secretlyQuestionResponse.setDes("请重新登陆");
				}
	
			//} else {
				// 重新登录
				//secretlyQuestionResponse.setCode("2");
				//secretlyQuestionResponse.setDes("请重新登陆");
			//}
			logger.info("返回："
					+ mapper.writeValueAsString(secretlyQuestionResponse));
		} catch (Exception e) {

			e.printStackTrace();
			secretlyQuestionResponse.setCode("0");
			secretlyQuestionResponse.setDes("系统繁忙请稍后再试！");
		}

		return secretlyQuestionResponse;
	}

	/**
	 * 获取用户的所有信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/message", method = RequestMethod.POST)
	@ResponseBody
	public Object userAllMessage(HttpServletRequest request) {
		LoginResponse loginResponse = new LoginResponse();
		try {
			
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				// String phoneNumber = redisService.get(cookieId);
				if (cookieUser != null) {
					String phoneNumber = cookieUser.getPhoneNumber();
					User user = userService.getUserByPhoneNumber(phoneNumber);
					//问答卡余额
					loginResponse.setQACardBlance(user.getQACardBlance());
					if(user!=null){
						if (user.getSex() == null) {
							loginResponse.setGender("男");
						} else if (user.getSex() == 2) {
							loginResponse.setGender("女");
						} else {
							loginResponse.setGender("男");
						}
						if (user.getBirthdayDate() != null) {

							SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
							String format = dateFormater.format(user.getBirthdayDate());
							
							loginResponse.setBirthday(format);
						}
						String counselorDuty = user.getCounselorDuty();
						if(counselorDuty!=null){
							StringBuilder stringBuilder=new StringBuilder();
							String[] split = counselorDuty.split(",");
							
							for (String id : split) {
								if(id!=null&&!id.equals("")){
									Duty duty = counselorDutyService.getDutyById(id);
									if(duty!=null){
										
										stringBuilder.append(duty.getDutyName()+" ");
									}
								}
								
							}
							user.setCounselorDuty(stringBuilder.toString());
							
						}
						BeanUtils.copyProperties(loginResponse, user);

						Integer companyRole = user.getCompanyRole();
						String counselorUuid = user.getCounselorUuid();
						if (counselorUuid != null&&!counselorUuid.equals("")) {
							Counselor counselor = counselorService
									.getCounselorByUuid(counselorUuid);
							if (counselor != null) {
								// 申请了咨询师

								Date applyDate = counselor.getApplyDate();
								if (applyDate != null) {
									loginResponse.setApplyTime(applyDate);
								}
								String counselorLevel = counselor
										.getCounselorLevel();

								if (StringUtils.isNotBlank(counselorLevel)) {
									
									Level level = levelService
											.getLevelByUuid(counselorLevel);
									if (level!=null) {
										loginResponse.setLevelName(level.getName());
										loginResponse.setLevelMoney(level.getMoney());
									}
									
								}

								String adept = counselor.getAdept();
								if (adept != null && !adept.equals("")) {
									String[] adeps = adept.split(",");
									HashMap<String, String> map = new HashMap<String, String>();
									for (String categoyrUuid : adeps) {
										if (categoyrUuid != null) {
											Category categoryById = categoryService
													.getCategoryById(categoyrUuid);
											if (categoryById != null) {
												map.put(categoyrUuid,
														categoryById.getName());
											}

										}

									}
									loginResponse.setAdepts(map);
								}
								BeanUtils.copyProperties(loginResponse, counselor);
								loginResponse.setIdCard(counselor.getIDCard());
								loginResponse.setIdCardBack(counselor.getIDCardBack());
								loginResponse.setIdCardFront(counselor.getIDCardFront());
								
							} 
						}
						if (companyRole == 1 || companyRole == 2) {
							// 申请了企业用户
							String companyUuid = user.getCompanyUuid();
							Company company = companyService
									.getCompanyByUuid(companyUuid);
							if (company != null) {
								loginResponse
										.setCompanyStataus(company.getStatus());
								loginResponse.setLicenseImage(company
										.getLicenseImage());
								loginResponse.setBusinessBalance(company.getBusinessBalance());
							} 
						}
						Integrals integrals = IntegralService.getIntegralsByUuid(phoneNumber);
						if (integrals==null) {
							loginResponse.setIntegralScore(0);
						}else {
							int integralSum = integrals.getIntegralSum();
							loginResponse.setIntegralScore(integralSum);
						}
						
						
						loginResponse.setCode("1");
						
					}
					//当前用户是否存在密码
					if(StringUtils.isBlank(user.getPwd())){
						loginResponse.setIfPwd(0);
					}else{
						loginResponse.setIfPwd(1);
					}
				} else {
					// 重新登录
					loginResponse.setCode("2");
					loginResponse.setDes("重新登录");
				}
		} catch (Exception e) {
			e.printStackTrace();
			loginResponse.setCode("0");
			loginResponse.setDes("系统异常");
		}
		return loginResponse;
	}
	// 获取用户的部分信息
		@RequestMapping(value = "/sectionMessage", method = RequestMethod.POST)
		@ResponseBody
		public Object userSectionMessage(HttpServletRequest request) {
			LoginResponse loginResponse = new LoginResponse();
			try {
				
					CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
					// String phoneNumber = redisService.get(cookieId);
					if (cookieUser != null) {
						String phoneNumber = cookieUser.getPhoneNumber();
						User user = userService.getUserByPhoneNumber(phoneNumber);
						if(user!=null){
							String counselorDuty = user.getCounselorDuty();
							if(counselorDuty!=null){
								StringBuilder stringBuilder=new StringBuilder();
								String[] split = counselorDuty.split(",");
								
								for (String id : split) {
									if(id!=null&&!id.equals("")){
										Duty duty = counselorDutyService.getDutyById(id);
										if(duty!=null){
											
											stringBuilder.append(duty.getDutyName()+" ");
										}
									}
									
								}
								//user.setCounselorDuty(stringBuilder.toString());
								
							}
							String counselorUuid = user.getCounselorUuid();
							Counselor counselor = counselorService.getCounselorByUuid(counselorUuid);
							if(counselor!=null){
								
								loginResponse.setStatus(counselor.getStatus());
								String counselorLevel = counselor.getCounselorLevel();
								Level level = levelService.getLevelByUuid(counselorLevel);
								if(level!=null){
									String name = level.getName();
									Integer money = level.getMoney();
									loginResponse.setLevelName(name);
									loginResponse.setLevelMoney(money);
								}
							}
							loginResponse.setBalance(user.getBalance());
							loginResponse.setCompanyRole(user.getCompanyRole());
							loginResponse.setRole(user.getRole());
							loginResponse.setVipBalance(user.getVipBalance());
							loginResponse.setUserName(user.getUserName());
							loginResponse.setVip(user.getVip());
							loginResponse.setVideoNum(user.getVideoNum());
							loginResponse.setAdvisoryNum(user.getAdvisoryNum());
							
							Integer companyRole = user.getCompanyRole();
							
							
							if (companyRole == 1 || companyRole == 2) {
								// 申请了企业用户
								String companyUuid = user.getCompanyUuid();
								Company company = companyService
										.getCompanyByUuid(companyUuid);
								if (company != null) {
									loginResponse
											.setCompanyStataus(company.getStatus());
									loginResponse.setBusinessBalance(company.getBusinessBalance());
								} 
							}
							Integrals integrals = IntegralService.getIntegralsByUuid(phoneNumber);
							if (integrals==null) {
								loginResponse.setIntegralScore(0);
							}else {
								int integralSum = integrals.getIntegralSum();
								loginResponse.setIntegralScore(integralSum);
							}
							loginResponse.setCode("1");
						
						}else {
							loginResponse.setCode("2");
							loginResponse.setDes("重新登录");
						}
				} else {
						// 重新登录
						loginResponse.setCode("2");
						loginResponse.setDes("重新登录");
					}
				
			} catch (Exception e) {
				e.printStackTrace();
				loginResponse.setCode("0");
				loginResponse.setDes("系统异常");
			}
			return loginResponse;
		}

	// 添加员工接口
	@RequestMapping(value = "/addCompanyUser", method = RequestMethod.POST)
	@ResponseBody
	public Object addCompanyUser(HttpServletRequest request,
			@RequestBody FindPwdOneRequest addCompanyUserRequest) {
		FindPwdOneResponse addCompanyUserResponse = new FindPwdOneResponse();
		try {
			//String cookieId = request.getHeader("cookieId");
			//if (cookieId != null) {
				//CookieUser cookieUser = redisService.getObejct(cookieId,
						//CookieUser.class);
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if (cookieUser != null) {

					String phoneNumber = cookieUser.getPhoneNumber();
					User user = userService.getUserByPhoneNumber(phoneNumber);
					if(user!=null){
						Integer companyRole = user.getCompanyRole();
						String companyUuid = user.getCompanyUuid();
						if (companyRole == 1) {
							String phoneNum = addCompanyUserRequest
									.getPhoneNumber();
							User user2 = userService.getUserByphone(phoneNum);
							//User user2 = userService.getUserByPhoneNumber(phoneNum);
							if (user2 != null) {
								if (companyUuid != null) {
									Company company = companyService
											.getCompanyByUuid(companyUuid);
									if (company != null) {
										Integer companyRole2 = user2
												.getCompanyRole();
										if (companyRole2 == 1 || companyRole2 == 2) {
											String companyUuid2 = user2
													.getCompanyUuid();
											if (companyUuid2.equals(companyUuid)) {
												// 已经是公司的人了
												addCompanyUserResponse.setCode("3");
												addCompanyUserResponse
														.setDes("此用户已加入本公司了");
											} else {
												// 已经加入其它公司
												addCompanyUserResponse.setCode("3");
												addCompanyUserResponse
														.setDes("此用户已加入其它公司");
											}

										} else {
											String companyName = company
													.getCompanyName();
											User user3 = new User();
											//Double vipBalance = user2.getVipBalance();
											//钱不合并了
											//Double businessBalance = company.getBusinessBalance();
											//company.setBusinessBalance(businessBalance+vipBalance);
											//user3.setVipBalance(0.0); 
											String phoneNumber2 = user2.getPhoneNumber();
											user3.setPhoneNumber(phoneNumber2);
											user3.setCompanyUuid(companyUuid);
											user3.setCompanyName(companyName);
											user3.setCompanyRole(2);
											//userService.updateUserAndCompany(user3, company, vipBalance);
											userService.updateUser(user3);
											addCompanyUserResponse.setCode("1");
										}

									} else {
										// 数据格式错误
										addCompanyUserResponse.setCode("3");
										addCompanyUserResponse.setDes("数据格式错误！");
									}

								} else {
									// 数据格式错误
									addCompanyUserResponse.setCode("3");
									addCompanyUserResponse.setDes("数据格式错误！");
								}

							} else {
								// 此用户没有注册
								addCompanyUserResponse.setCode("3");
								addCompanyUserResponse.setDes("此用户还没有注册");
							}
						} else {
							// 你没有权限
							addCompanyUserResponse.setCode("3");
							addCompanyUserResponse.setDes("你没有权限！");
						}

					}else {
						// 重新登录、
						addCompanyUserResponse.setCode("2");
						addCompanyUserResponse.setDes("重新登录！");
					}
				} else {
					// 重新登录、
					addCompanyUserResponse.setCode("2");
					addCompanyUserResponse.setDes("重新登录！");
				}
			//} else {
				// 重新登录
				//addCompanyUserResponse.setCode("2");
				//addCompanyUserResponse.setDes("重新登录！");
			//}
		} catch (Exception e) {
			e.printStackTrace();
			addCompanyUserResponse.setCode("0");
			addCompanyUserResponse.setDes("系统繁忙");
		}
		return addCompanyUserResponse;
	}

	// 员工列表接口
	@RequestMapping(value = "/allCompamyUser", method = RequestMethod.POST)
	@ResponseBody
	public Object allCompamyUser(HttpServletRequest request) {
		AllCompanyUserResponse allCompanyUserResponse = new AllCompanyUserResponse();
		try {
			//String cookieId = request.getHeader("cookieId");
			//if (cookieId != null) {
				//CookieUser cookieUser = redisService.getObejct(cookieId,
						//CookieUser.class);
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if (cookieUser != null) {
					String phoneNumber = cookieUser.getPhoneNumber();
					User user = userService.getUserByPhoneNumber(phoneNumber);
					if (user != null) {
						String companyUuid = user.getCompanyUuid();
						UserExample example = new UserExample();
						example.setOrderByClause("phone");
						com.jieshuibao.model.db.UserExample.Criteria criteria = example
								.createCriteria();
						criteria.andCompanyUuidEqualTo(companyUuid);
						Company company = companyService.getCompanyByUuid(companyUuid);
						if(company!=null){
							allCompanyUserResponse.setCompanyLog(company.getCompanyLog());
							List<User> users = userCompanyService.getUserCompany(example);
							allCompanyUserResponse.setUsers(users);
							allCompanyUserResponse.setCode("1");
						}else {
							allCompanyUserResponse.setCode("3");
							allCompanyUserResponse.setDes("数据格式错误");
						}
					} else {
						// 重新登录
						allCompanyUserResponse.setCode("2");
						allCompanyUserResponse.setDes("重新登录！");
					}
				} else {
					// 重新登录
					allCompanyUserResponse.setCode("2");
					allCompanyUserResponse.setDes("重新登录！");
				}
			//} else {
				// 重新登录
				//allCompanyUserResponse.setCode("2");
				//allCompanyUserResponse.setDes("重新登录！");
			//}
		} catch (Exception e) {
			e.printStackTrace();
			allCompanyUserResponse.setCode("0");
			allCompanyUserResponse.setDes("系统繁忙");
		}
		return allCompanyUserResponse;
	}

	// 转让管理员
	@RequestMapping(value = "/changeAdmin", method = RequestMethod.POST)
	@ResponseBody
	public Object changeAdmin(HttpServletRequest request,
			@RequestBody FindPwdOneRequest addCompanyUserRequest) {
		AllCompanyUserResponse changeAdminResponse = new AllCompanyUserResponse();
		try {
			logger.debug("接收：" + mapper.writeValueAsString(addCompanyUserRequest));
			//String cookieId = request.getHeader("cookieId");
			//if (cookieId != null) {
				//CookieUser cookieUser = redisService.getObejct(cookieId,
						//CookieUser.class);
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if (cookieUser != null) {
					String phoneNumber = cookieUser.getPhoneNumber();
					User user = userService.getUserByPhoneNumber(phoneNumber);
					if (user != null) {
						Integer companyRole = user.getCompanyRole();
						String companyUuid = user.getCompanyUuid();
						if (companyRole == 1) {
							String phoneNum = addCompanyUserRequest
									.getPhoneNumber();
							Company company = companyService
									.getCompanyByUuid(companyUuid);
							//User user2 = userService.getUserByPhoneNumber(phoneNum);
									
							User user2 = userService.getUserByphone(phoneNum);
							if (company != null && user2 != null) {
								String phoneNumber2 = user2.getPhoneNumber();
								if(phoneNumber2.equals(phoneNumber)){
									changeAdminResponse.setCode("3");
									changeAdminResponse.setDes("你不能转让给自己");
								}else {
									company.setPhoneNumber(phoneNumber2);
									User user3 = new User();
									User user4 = new User();
									user3.setPhoneNumber(phoneNumber);
									user3.setCompanyRole(2);
									user4.setPhoneNumber(phoneNumber2);
									user4.setCompanyRole(1);
									changeAdminService.updateComapnyRole(user3,
											user4, company);
									// 
									changeAdminResponse.setCode("1");
									changeAdminResponse.setDes("转让成功");
								}
								
							
							} else {
								// 数据格式错误
								changeAdminResponse.setCode("3");
								changeAdminResponse.setDes("数据格式错误！");
							}
						} else {
							// 你没有权限
							changeAdminResponse.setCode("3");
							changeAdminResponse.setDes("你没有权限");
						}
					} else {
						// 请重新登录
						changeAdminResponse.setCode("2");
						changeAdminResponse.setDes("请重新登录");
					}
				} else {
					// 请重新登录
					changeAdminResponse.setCode("2");
					changeAdminResponse.setDes("请重新登录");
				}
			//} else {
				// 请重新登录
				//changeAdminResponse.setCode("2");
				//changeAdminResponse.setDes("请重新登录");

			//}
		} catch (Exception e) {
			e.printStackTrace();
			changeAdminResponse.setCode("0");
			changeAdminResponse.setDes("系统繁忙");
		}

		return changeAdminResponse;
	}

	// 移除企业用户
	@RequestMapping(value = "/remove", method = RequestMethod.POST)
	@ResponseBody
	public Object deleteCompanyUser(HttpServletRequest request,
			@RequestBody FindPwdOneRequest addCompanyUserRequest) {
		AllCompanyUserResponse deleteCompanyUserResponse = new AllCompanyUserResponse();

		try {
			//String cookieId = request.getHeader("cookieId");
			//if (cookieId != null) {
				//CookieUser cookieUser = redisService.getObejct(cookieId,
						//CookieUser.class);
				CookieUser cookieUser = (CookieUser)request.getAttribute("cookieUser");
				if (cookieUser != null) {
					String phoneNumber = cookieUser.getPhoneNumber();
					User user = userService.getUserByPhoneNumber(phoneNumber);
						if (user != null) {
							Integer companyRole = user.getCompanyRole();
							if (companyRole == 1) {
							String phoneNum = addCompanyUserRequest
									.getPhoneNumber();
							//User user2 = userService.getUserByPhoneNumber(phoneNum);
									
							User user2 = userService.getUserByphone(phoneNum);
							if (user2 != null) {
								String phoneNumber2 = user2.getPhoneNumber();
								
								if(phoneNumber2.equals(phoneNumber)){
									deleteCompanyUserResponse.setCode("3");
									deleteCompanyUserResponse.setDes("你不能删除自己");
								}else {
									User user3 = new User();
									user3.setPhoneNumber(phoneNumber2);
									user3.setCompanyRole(0);
									user3.setCompanyUuid("");
									userService.updateUser(user3);
									deleteCompanyUserResponse.setCode("1");
									deleteCompanyUserResponse.setDes("删除成功");
								}
								
							} else {
								// 数据格式错误
								deleteCompanyUserResponse.setCode("3");
								deleteCompanyUserResponse.setDes("数据格式错误！");
							}
						} else {
							
							// 没有权限
							deleteCompanyUserResponse.setCode("3");
							deleteCompanyUserResponse.setDes("你没有权限！");
						}
					} else {
						// 重新登录
						deleteCompanyUserResponse.setCode("2");
						deleteCompanyUserResponse.setDes("重新登录");
					}

				} else {
					// 重新登录
					deleteCompanyUserResponse.setCode("2");
					deleteCompanyUserResponse.setDes("重新登录");
				}
			//} else {
				// 重新登录
				//deleteCompanyUserResponse.setCode("2");
				//deleteCompanyUserResponse.setDes("重新登录");
			//}
		} catch (Exception e) {
			e.printStackTrace();
			deleteCompanyUserResponse.setCode("0");
			deleteCompanyUserResponse.setDes("系统繁忙");
		}
		return deleteCompanyUserResponse;
	}
	
	
}
